package com.ninghushangbao.ninghu.controller;

import com.ninghushangbao.ninghu.controller.vo.ResultEntity;
import com.ninghushangbao.ninghu.entity.Product;
import com.ninghushangbao.ninghu.service.ProductService;
import com.ninghushangbao.ninghu.utils.BaseResult.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/product")
@CrossOrigin()
public class ProductController {

    @Autowired
    ProductService productService;

    @PostMapping("/pd_add")
    public ResultEntity addProduct(@RequestBody Product product){
        System.out.println(product);
        productService.addProduct(product);
        return ResultUtil.success();
    }

    @GetMapping("/sel_all")
    public ResultEntity selectProduct(){
        List<Product> products = productService.selectProduct();
        return ResultUtil.success(products);
    }

    @DeleteMapping("/pd_del")
    public ResultEntity deleteProduct(@RequestBody List<Integer> list){
        productService.deleteProductById(list);
        return ResultUtil.success();
    }

    @PutMapping("/pd_mod")
    public ResultEntity updateProduct(@RequestBody Product product){
        productService.updateProduct(product);
        return ResultUtil.success();
    }

}
